﻿using Moq;
using System;
using System.IO;
using System.Threading.Tasks;
using TabbedTemplate.Services;

namespace UnitTest.helpers
{
    public static class QueryCacheHelper
    {
        /// <summary>
        /// 删除数据库文件。
        /// </summary>
        public static void RemoveDatabaseFile()
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
            File.Delete(Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder
                    .LocalApplicationData), QueryService.DbName));
        }

        /// <summary>
        /// 获得已初始化的诗词存储。
        /// </summary>
        public static async Task<QueryService> GetInitializedQueryCache()
        {
            var queryService =
                new QueryService(new Mock<IPreferenceStorage>().Object);
            await queryService.InitializeAsync();
            return queryService;
        }
    }
}
